package org.example.preparelessons.config;

import org.example.preparelessons.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer
{   //主要用于实现无业务逻辑跳转，例如主页跳转，
    // 简单的请求重定向，错误页跳转等
     @Override
     public void addViewControllers(ViewControllerRegistry registry)
     {
         registry.addViewController("/").setViewName("login");
         registry.addViewController("/index.html").setViewName("login");
         registry.addViewController("/main.html").setViewName("main");
     }
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        System.out.println("MyMvcConfig.addInterceptors 注册拦截器");
        registry.addInterceptor(new LoginInterceptor())//注册拦截器
                .addPathPatterns("/**")
                .excludePathPatterns("/", "/login", "/index.html", "/user/login", "/css/**", "/images/**", "/js/**", "/fonts/**");//放行登录页，登陆 操作，静态资源
        }
}
